﻿using Hotel_Project.Bean;
using Hotel_Project.BIZ;
using Hotel_Project.Tools.AddForm_Helps;
using Hotel_Project.Tools.BrushMenuStrip;
using Hotel_Project.Tools.MySqlData_Helps;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Hotel_Project.HotelForm
{
    /// <summary>
    /// 蒋佳峻写    用户管理
    /// </summary>
    public partial class UserManagement : Form
    {
        public UserManagement()
        {
            InitializeComponent();
        }
        public UserMenuJurisdiction form = new UserMenuJurisdiction();
        private void UserManagement_Load(object sender, EventArgs e)
        {
            ControlUtils.AddTabFormPage(tabControl1,form);
            Fulsh(adminDataView);
        }
        public async void Fulsh(DataGridView da)
        {
            MySqlDataTable de = new MySqlDataTable();
            DataTable data = await de.GetDataTable(MySqlString.MYSQL_CONNAND, MySqlString.MYSQL_SELECT_admin);
            data.Columns[0].ColumnName = "用户账号";
            data.Columns[1].ColumnName = "用户密码";
            data.Columns[2].ColumnName = "用户职位";
            data.Columns[3].ColumnName = "用户姓名";
            data.Columns[4].ColumnName = "用户状态";
            da.DataSource = data;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                UserManage.getFrom(this).Show();
            }catch (Exception ex) { }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var arr=form.treeView1.Nodes;
            foreach (TreeNode row in arr)
            {
                //当树的父节点有为false的时候
                if (row.Checked == false)
                {
                    int paper = -1;
                    for (int i=0;i<Form1.form1.menuStrip.Items.Count;i++)
                    {
                        if (row.Text.Equals(Form1.form1.menuStrip.Items[i].Text))
                        {
                            paper = i;
                            break;
                        }
                    }
                    if (paper!=-1)
                    {
                        Form1.form1.menuStrip.Items.RemoveAt(paper);
                    }
                }
                var crr = row.Nodes;
                foreach (TreeNode item in crr)
                {
                    //当树的子节点有为false的时候
                    if (item.Checked == false)
                    {
                        Console.WriteLine(item.Text);
                        Ztool(row,item);
                    }
                }
            }
        }
        private void Ztool(TreeNode fu,TreeNode zi)
        {
            int Count = 0;
            foreach (ToolStripMenuItem item in Form1.form1.menuStrip.Items)
            {
                if (fu.Text.Equals(item.Text))
                {
                    for (int j = 0; j < item.DropDownItems.Count; j++)
                    {
                        if (zi.Text.Equals(item.DropDownItems[j].Text))
                        {
                            //必须先转为(ToolStripMenuItem)类型才可以拿到子节点的集合
                            ((ToolStripMenuItem)Form1.form1.menuStrip.Items[Count]).DropDownItems.RemoveAt(j);
                        }
                    }
                }
                Count++;
            }
            for(int i = 0;i<Form1.form1.menuStrip.Items.Count;i++)
            {
                ToolStripMenuItem tool=((ToolStripMenuItem)Form1.form1.menuStrip.Items[i]);
                for (int j = 0; j < tool.DropDownItems.Count; j++)
                {

                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1.form1.menuStrip.Items.Clear();
            //加载菜单栏
            AddMenuStrip am = new AddMenuStrip();
            am.AddListMenuStrip(Form1.form1.menuStrip, Form1.form1.homeTableControl);
        }
    }
}
